<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>

<head>
    <title><spring:message code="message.lable.compdrugprofileSTDmanage"></spring:message></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
    <link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <style type="text/css">
       .inf{
           position:fixed;
           top:150px;
           right:35px;
           width:150px;
           height:250px;
           background-color:#3c8dbc;
           z-index:999;
        }
        p.infTitle{
           color:#fff;
           margin-left:10px;
           margin-top:8px;
           line-height:10px;
        }
        p.infWord{
          color:#e1ebf3;
          margin-left:10px;
          line-height:12px;
        }
        .opacity50 { /* 75% opaque */
            opacity:0.75;
            -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=75)";
            filter:alpha(opacity=75);
            zoom:1
        }
        #shclNs {
           position:fixed;
           left:0px;
           top:0px;
           width:100%;
           height:100%;
           opacity:0.75;
           -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=75)";
           filter:alpha(opacity=75);
           background-color: gray;
           margin:0px;
           padding:0px;
           z-index:999999;
           background:url('${ctx}/lib/img/loading.gif') no-repeat center center;
        }
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame" style="height:100%;">
    
    <section class="content-header">
        <h1><spring:message code="message.jqGrid.cz.qualificationManagement"></spring:message></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.compdrugprofileStd"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.profileSeeStd"/></a></li>
        </ol>
    </section>
    
    <section class="content" style="min-height:0px;">
        <div class="box box-success">
            <div class="box-body">
                     <div class="input">
                     <div class="textalign1"><spring:message code="message.listForm.ziZhiMingCheng"></spring:message><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchProfileName" type="text" placeholder="<spring:message code="message.listForm.ziZhiMingCheng"/>" />
                    </div>
                    <div class="textalign1"><spring:message code="message.listForm.ZiZhiBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchProfileCode" type="text" placeholder="<spring:message code="message.listForm.ZiZhiBianMa"/>" />
                    </div>
           			
                    <div class="textalign1"><spring:message code="message.lable.status"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                       <select id="status" name="status" class="textinput">
                           	<option value="" ><spring:message code="message.select.option"/></option>
                            <option value="1" ><spring:message code="message.button.start"/></option>
                            <option value="0" ><spring:message code="message.button.stop"/></option>
                           </select>
                     </div>
                     <div class="textalign1" >
                    <button id="selectAudit" type="button" onclick="searchDrugProfile();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                </div>
                </div>
            </div>
        </div>
    </section>
    
    <section id="listPanel" class="content" style="min-height:0px;padding-top:0px;">
        <div id="scrollPanel" class="box box-primary" style="height:100%;overflow-y:auto;">
            <div id="wrapper" style="overflow:hidden;">
                <div id="content" style="overflow:hidden;"></div>
            </div>
        </div>
    </section>
    
    <section class="content-header" style="position:fixed;bottom:0px;left:0px;right:0px;">
        <div class=" box box-warning bottongroup">
            <ms:btn url="/compDrugProfile/add.html"><a id="addNew" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></a></ms:btn>
            <a href="javascript:history.go(-1)" class="btn btn-danger btn-sm"><spring:message code="message.button.getBackSpacing"/></a>
        </div>
    </section>
    
    <div class="opacity50 inf">
        <p class="infTitle"><b><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao" /></b></p>
        <p class="infWord"><c:out value="${drugInfo.drugCode}"></c:out></p>
        <p class="infTitle"><b><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao" /></b></p>
        <p class="infWord"><c:out value="${drugInfo.qualityspecName}"></c:out></p>
        <p class="infTitle"><b><spring:message code="message.listForm.jiXing"/><spring:message code="message.yanZheng.maoHao" /></b></p>
        <p class="infWord"><c:out value="${drugInfo.formName}"></c:out></p>
        <p class="infTitle"><b><spring:message code="message.listForm.guiGe"/><spring:message code="message.yanZheng.maoHao" /></b></p>
        <p class="infWord"><c:out value="${drugInfo.specName}"></c:out></p>
        <p class="infTitle"><b><spring:message code="message.listForm.shengChanQiYe"/><spring:message code="message.yanZheng.maoHao" /></b></p>
        <p class="infWord"><c:out value="${drugInfo.compName}"></c:out></p>
    </div>
    
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h5 class="modal-title" id="exampleModalLabel"><spring:message code="message.lable.DICyaoPinZiZhi"></spring:message> </h5>
                </div>
                <form id="form" action="${ctx}/compDrugProfile/saveDrugProfile.html" method="post" enctype="multipart/form-data">
                <div class="modal-body">
                    <div class="form-group form-group-xs" style="width:50%;float:left;padding-left:10px;">
                        <label for="recipient-name" class="control-label"><span class="required">*</span><spring:message code="message.lable.username" /><spring:message code="message.yanZheng.maoHao" /></label>
                        <div class="" >
                            <input type="text" class="form-control" id="profileName" name="profileName" placeholder="<spring:message code="message.lable.compdrugprofileSTDname" />" maxlength="128">
                        </div>
                    </div>
                    <div class="form-group form-group-xs"  style="width:50%;float:left;padding-left:10px;">
                        <label for="recipient-name" class="control-label"><span class="required">*</span><spring:message code="message.listForm.tuPian" /><spring:message code="message.yanZheng.maoHao" /></label>
                        <div class="">
                            <input id="acctApprovalPicDir" name="profile" type="file" style="display:inline-none;" />
                        </div>
                    </div>
                    <div class="form-group form-group-xs" style="width:100%;float:left;padding-left:10px;">
                        <label for="recipient-name" class="control-label"><span class="required">*</span><spring:message code="message.lable.type" /><spring:message code="message.yanZheng.maoHao" /></label>
                        <div class="" >
                           <select class="form-control" id="profileType" name="profileType">
                             <option value=""><spring:message code="message.select.option" /></option>
                             <c:if test="${typeList != null}">
                                 <c:forEach items="${typeList}" var="type">
                                    <option value="${type.id}">${type.name}</option>
                                 </c:forEach>
                             </c:if>
                           </select>
                        </div>
                    </div>
                    
                    <div class="form-group form-group-xs" style="width:100%;float:left;padding-left:10px;">
                        <label><span class="required">*</span><spring:message code="message.listForm.youXiaoQi" /><spring:message code="message.yanZheng.maoHao" /></label>
                         <table style="width:100%;">
		                                <tr>
		                                    <td style="width:50%">
		                                        <input  type="text" style="width: 100%;" name="profileStarttime" id="createTimeBegin" placeholder="yyyy-MM-dd"
                              onFocus="var endDate=$dp.$('createTimeEnd');WdatePicker({maxDate:'#F{$dp.$D(\'createTimeEnd\')}'})" maxlength="25"/>
		                                    </td>
		                                    <td>&nbsp;-&nbsp;</td>
		                                    <td style="width:50%">
		                                        <input  type="text" style="width: 100%;" name="profileEndtime" id="createTimeEnd" placeholder="yyyy-MM-dd" maxlength="25"
                                onFocus="WdatePicker({minDate:'#F{$dp.$D(\'createTimeBegin\')}'})" />
		                                    </td>
		                                </tr>
		                         </table>
                    </div>
                    <div class="form-group form-group-xs" style="width:100%;float:left;padding-left:10px;">
                        <label for="txtDrugForm"><spring:message code="message.listForm.beiZhu" /><spring:message code="message.yanZheng.maoHao" /></label>
                        <textarea class="form-control"  placeholder="备注" id="remark" name="remark" maxlength="512"></textarea>
                   </div>
                   <input type="hidden" id="compprofileId" name="compProfileId" />
                   <input type="hidden" name="prodId" value="${prodId}" />
                   <input type="hidden" name="compId" value="${compId}" />
                </div>
                </form>
                <div class="modal-footer"   >
                    <button type="button" class="btn btn-primary btn-sm" id="submitDicCompType" onclick="save();"><spring:message code="message.button.saveSpacing" /></button>
                    <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal" id="closeDicCompType"><spring:message code="message.button.closeSpacing" /></button>
                </div>
            </div>
        </div>
    </div>
    
    <div id="shclNs"></div>
    
    <script id="test" type="text/html">
        {{each rows as row i}}
            <div class="col-xs-6 col-lg-4 hei" style="height:450px;">
                <div class="wrapper2 ">
                    <a id=""  href="javascript:showImg('{{row.profilePicAddr}}','{{row.profileName}}');" ><img class="img-responsive" border="0" src="${ctx}/{{row.profilePicShortcutAddr}}" onerror="this.src='${ctx}/upload/image/nothing.jpg'" /></a>
                    <div class="row" style=" margin-left: -12;margin-left: -23px;">
                        <div class="col-md-12">
                            <p class="pull-left imgButton">
                                <ms:btn url="/compDrugProfile/add.html"><button type="button" class="btn btn-primary btn-sm" style="margin-left: 1px;" onclick="edit('{{row.compprofileId}}','{{row.profileCode}}','{{row.profileName}}','{{row.profileType}}','{{row.profileStarttime}}','{{row.profileEndtime}}','{{row.profilePicAddr}}','{{row.remark}}','{{row.profilePicAddr}}');" style="margin-left:10px"><spring:message code="message.button.editSpacing" /></button></ms:btn>
                                {{if row.status == 1}}
                                    <ms:btn url="/compDrugProfile/disabled.html"><button type="button" class="btn btn-primary btn-sm" onclick="changeStatus('{{row.compprofileId}}','{{row.status}}','{{row.profileName}}');"><spring:message code="message.button.stopSpacing" /></button></ms:btn>
                                    {{else}}
                                    <ms:btn url="/compDrugProfile/enabled.html"><button type="button" class="btn btn-primary btn-sm" onclick="changeStatus('{{row.compprofileId}}','{{row.status}}','{{row.profileName}}');"><spring:message code="message.button.startSpacing" /></button></ms:btn>
                                {{/if}}
                                <ms:btn url="/stdCompdrugprofile/toStdCompdrugprofileLogList.html"><a class="btn btn-primary btn-sm" href="${ctx}/stdCompdrugprofile/toStdCompdrugprofileLogList.html?compprofileId={{row.compprofileId}}&profileCode={{row.profileCode}}&profileName={{row.profileName}}"><spring:message code="message.jqGrid.cz.weiHuJiLu" /></a></ms:btn>
                            </p>
                        </div>  
                    </div>
                    <div class="row" style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.bianHao" />:<span class="productInfo" name="profileCode" >{{row.profileCode}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.yanZheng.mingChen" />:<span class="productInfo" name="profileName" >{{row.profileName}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.mingCheng" />:<span class="productInfo" name="profileType" >{{row.firstLevelIndiName}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                 <div class="productInfo" >&nbsp;<spring:message code="message.listForm.youXiaoQi" />:<span class="productInfo" name="profileTime" >&nbsp;{{row.profileStarttime}}&nbsp;&nbsp;<spring:message code="message.listForm.zhi" />&nbsp;&nbsp;{{row.profileEndtime}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.lable.zhuangTai" />:<span class="productInfo" name="status" >{{row.status | formatStatus}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.beiZhu" />:<span class="productInfo" name="remarks" >{{row.remark}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.shenHeZhuanTai" />:<span class="productInfo" name="auditStatus" >{{row.auditStatus | formatAuditStatus}}</span></div>
                            </p>
                        </div>
                    </div>
                    <div class="row"  style="margin-left:0px">
                        <div class="col-md-12">
                            <p class="pull-left">
                                <div class="productInfo" >&nbsp;<spring:message code="message.listForm.shenHeBeiZhu" />:<span class="productInfo" name="auditRemark" >{{row.auditRemark}}</span></div>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        {{/each}}
    </script>

    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    //绑定回车
    $('#searchProfileCode,#searchProfileName,#auditStatus').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectAudit').click();
        }
    }); 
  
    $("#searchProfileName").focus();//加载页面光标在第一个查询框内
    
        var opType = 0; //  0新增，1编辑
        var records = 0;//总条目
        var postData = {"rows":6,"page":1,"prodId":"${prodId}","compId":"${compId}"};//rows 一页展示多少条   page当前页数
    
        function resizeListHeight() {
            var windowHeight = $(window).height() || 0;
            var topHeight = $("#listPanel").position().top || 0;
            var bottomHeight = 75;
            var height = windowHeight - topHeight - bottomHeight;
            height = height < 0 ? 0 : height;
            $("#listPanel").height(height);
        }
        
        function getList(postData){
            $("#shclNs").show();
            $.post('${ctx}/compDrugProfile/getCompDrugProfileList.html', postData, function(result) {
                if (result.success) {
                    $("#shclNs").hide();
                    var html = template('test', result);
                    $('#content').append(html);
                    records = result.records;  //总条数
                }
            }, "json");
        }
        
        function searchDrugProfile() {
            var profileCode = $.trim($("#searchProfileCode").val());
            var profileName = $.trim($("#searchProfileName").val());
            var auditStatus = $.trim($("#auditStatus").val());
            postData["profileCode"] = profileCode;
            postData["profileName"] = profileName;
            postData["auditStatus"] = auditStatus;
            postData["page"] = 1;
            $('#content').children().remove();
            getList(postData);
        }
        
        //提交
        function changeStatus(compprofileId, status,profileName) {
            var msg = status == 1 ? "<spring:message code='message.lable.OKYES' /><spring:message code='message.button.stop' />"+profileName+"<spring:message code='message.HN.alert.ziZhiMa' />" : "<spring:message code="" /><spring:message code='message.lable.OKYES' /><spring:message code='message.button.start' />"+profileName+"<spring:message code="message.HN.alert.ziZhiMa" />";
            $.HN.message.confirm(msg, '', '').on(function (e) {
                 if (e) {
                     var url = "${ctx}/compDrugProfile/" + (status == 1 ? "disabled.html" : "enabled.html");
                    $.post(url, {
                        "compProfileId" : compprofileId
                    }, function(result) {
                        if (result.success) {
                        	searchDrugProfile();
                            $.alert("<spring:message code='message.HN.alert.success' />", "success");
                        } else {
                            $.alert("<spring:message code='message.HN.alert.fail' />", "error");
                        }
                    }, "json");
                 }
             }); 
        }  
        
        function edit(compprofileId, profileCode,profileName,profileType,profileStarttime,profileEndtime,profilePicAddr,remarks,compId) {
            opType = 1;
            $('#compprofileId').val(compprofileId);
            $('#profileCode').val(profileCode);
            $('#profileName').val(profileName);
            $("#profileType").val(profileType);
            $('#createTimeBegin').val(profileStarttime);
            $('#createTimeEnd').val(profileEndtime);
            $('#url2').attr("src","${ctx}/"+profilePicAddr);
            $('#url').attr("href","javascript:showImg('"+profilePicAddr+"','"+profileName+"');");
            
            $('#remark').val(remarks);
            $('#acctApprovalPicDir').val("");
            $('#exampleModalLabel').html("<spring:message code='message.lable.compdrugprofileSTDedit' />");
            $('#exampleModal').modal({
                keyboard : true
            });
        }

        function validate() {
            var profileName = $.trim($("#profileName").val());
            if (profileName == null || profileName == "") {
                $.alert("<spring:message code='message.HN.alert.pleaseInputYPZZName' />", "warn");
                return false;
            }
            
            var profileType = $.trim($("#profileType").val());
            if (profileType == null || profileType == "") {
                $.alert("<spring:message code='message.HN.alert.pleaseInputYPZZType' />", "warn");
                return false;
            }
            
            if (opType == 0) {  //  新增时必须上传资质图片
                var acctApprovalPicDir = $.trim($("#acctApprovalPicDir").val());
                if (acctApprovalPicDir == null || acctApprovalPicDir == "") {
                    $.alert("<spring:message code='message.HN.alert.pleaseInputYPZZIMG' />", "warn");
                    return false;
                }
            }
            
            var createTimeBegin = $.trim($("#createTimeBegin").val());
            if (createTimeBegin == null || createTimeBegin == "") {
                $.alert("<spring:message code='message.HN.alert.pleaseSelectStartTime' />", "warn");
                return false;
            }

            var createTimeEnd = $.trim($("#createTimeEnd").val());
            if (createTimeEnd == null || createTimeEnd == "") {
                $.alert("<spring:message code='message.HN.alert.pleaseSelectEndTime' />", "warn");
                return false;
            }
            return true;
        }
        
        //保存
        function save() {
            if (validate()) {
                $.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO" />', '<spring:message code="message.HN.alert.tiShiXinXi" />', '<spring:message code="message.lable.OKYES" />').on(function(e) {
                    if (e) {
                    	
                    	var url = "${ctx}/compDrugProfile/add.html";
                        if(compprofileId !=null && compprofileId != ""){     
                        	url = "${ctx}/compDrugProfile/edit.html";    
                        	}
                    	
                        $("#form").ajaxSubmit({
                        	url:url,
                            dataType : "json",
                            timeout : 10000,
                            success : function(result, statusText) {
                                if (result.success) {
                                    searchDrugProfile();
                                    $('#exampleModal').modal('hide');
                                    $.alert("<spring:message code='message.HN.alert.success' />", "success");
                                } else {
                                    $.alert(result.msg || "<spring:message code='message.HN.alert.fail' />", "error");
                                }
                            }
                        });
                    }
                });
            }
        }
        
        function showImg(imgPath, profileName) {
            var url = "${ctx}/acctInfo/toImg.html";
            $.HN.dialog.open({
                "id" : "showImg",
                "title" : profileName,
                "url" : url,
                "data" : {
                    "imgPath" : imgPath
                },
                "width" : 800,
                "height" : 400
            });
        }
    
        $(document).ready(function() {
            template.helper('formatStatus', function(data) {
                return data == 1 ? "<spring:message code='message.button.start' />" : "<spring:message code='message.button.stop' />";
            });

            template.helper('formatAuditStatus', function(data) {
                if (data == 0) {
                    return "<spring:message code='message.select.weishenhe' />";
                } else if (data == 1) {
                    return "<spring:message code='message.button.auditOK' />";
                } else if (data == 2) {
                    return "<spring:message code='message.button.auditNO' />";
                } else {
                    return "<spring:message code='message.select.weitijiao' />";
                }
            });
            
            $('#addNew').click(function() {
                opType = 0;
                $('#compprofileId').val("");
                $('#profileCode').val("");
                $('#profileName').val("");
                $("#profileType").val("");
                $('#createTimeBegin').val("");
                $('#createTimeEnd').val("");
                $('#remark').val("");
                $('#acctApprovalPicDir').val("");
                $('#exampleModalLabel').html("<spring:message code='message.lable.compdrugprofileSTDadd' />");
                $('#exampleModal').modal({
                    keyboard : true
                });
            });
            
            $(window).resize(function() {
                resizeListHeight();
            });
            
            var timer = null;
            
            $("#scrollPanel").scroll(function() {
                clearTimeout(timer);
                var scrollTop = $(this).scrollTop();
                var height = $("#wrapper").height() - $("#listPanel").height();
                timer = setTimeout(function() {
                    if (scrollTop >= height) {
                        postData.page++;
                        if (postData.page <= Math.ceil(records / postData.rows)) {
                            getList(postData);
                        } 
                    }
                }, 100);
            });
            
            resizeListHeight();
            getList(postData);
        });
    
        
    </script>

</body>
</html>

